<?php

	class UserIdentity extends CUserIdentity{
		private $_id;

		//Авторизация йопты
		public function authenticate(){
			$user=User::model()->find('LOWER(username)=?', array(strtolower($this->username)));
			if($user===NULL){
				$this->errorCode=self::ERROR_USERNAME_INVALID;
			}
			else{
				if(!$user->validatePassword($this->password)){
					$this->errorCode=self::ERROR_PASSWORD_INVALID;
				}
				else{
					$this->_id=$user->id;
					$this->username=$user->username;
					$this->errorCode=self::ERROR_NONE;
				}
			}
			return $this->errorCode==self::ERROR_NONE;
		}

		//Финишхим
		public function getId(){
			return $this->_id;
		}
	}
